package com.xmutca.sso.dao;

import com.xmutca.core.mybatis.MyBatisDao;
import com.xmutca.core.mybatis.lang.MybatisExtendedLanguageDriver;
import com.xmutca.sso.api.Permission;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author: 彭伟煌(pengweihuang@xmutca.com)
 * @create: 2016-08-29 15:53
 */
@MyBatisDao
public interface RolePermissionDao {

    /**
     * 角色权限新增
     * @param role
     * @param permission
     * @return
     */
    @Insert("insert into t_sys_role_permission(role, permission) values(#{role}, #{permission})")
    int add(@Param("role") Integer role, @Param("permission") Integer permission);

    /**
     * 角色权限删除
     * @param role
     * @param permission
     * @return
     */
    @Delete("delete t_sys_role_permission where role = #{role} and permission = #{permission}")
    int del(@Param("role") Integer role, @Param("permission") Integer permission);

    /**
     * 角色权限批量删除
     * @param permission
     * @return
     */
    @Delete("delete t_sys_role_permission where permission = #{permission}")
    int delByPermission(Integer permission);

    /**
     * 角色权限批量删除
     * @param permissions
     * @return
     */
    @Lang(MybatisExtendedLanguageDriver.class)
    @Delete("delete t_sys_role_permission where permission in (#{permissions})")
    int batchDelByPermissions(@Param("permissions") List<Integer> permissions);

    /**
     * 角色权限删除，根据角色
     * @param role
     * @return
     */
    @Delete("delete t_sys_role_permission where role = #{role}")
    int delByRole(Integer role);

    /**
     * 角色权限批量删除，根据角色
     * @param role
     * @return
     */
    @Lang(MybatisExtendedLanguageDriver.class)
    @Delete("delete t_sys_role_permission where role in (#{role})")
    int batchDelByRole(@Param("role") List<Integer> role);

    /**
     * 角色权限查询，根据角色读取
     * @param role
     * @return
     */
    @Select("select sp.* from t_sys_role_permission srp, t_sys_permission sp where srp.permission = sp.id and srp.role = #{role}")
    List<Permission> queryPermissionByRole(Integer role);
}
